Separation Logic
   HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includi ...
, separation logic is an extension of Hoare logic, a way of reasoning about programs. It was developed by
John C. Reynolds John Charles Reynolds (June 1, 1935 – April 28, 2013) was an American computer scientist. Education and affiliations John Reynolds studied at Purdue University and then earned a Doctor of Philosophy (Ph.D.) in theoretical physics from Harvard U ...
, Peter O'Hearn, Samin Ishtiaq and Hongseok Yang, drawing upon early work by
Rod Burstall Rodney Martineau "Rod" Burstall FRSE (born 1934) is a British computer scientist and one of four founders of the Laboratory for Foundations of Computer Science at the University of Edinburgh. Biography Burstall studied physics at the Universi ...
. The assertion language of separation logic is a special case of the logic of bunched implications (BI). A CACM review article by O'Hearn charts developments in the subject to early 2019.


Overview

Separation logic facilitates reasoning about: * programs that manipulate pointer data structures—including
information hiding In computer science, information hiding is the principle of segregation of the ''design decisions'' in a computer program that are most likely to change, thus protecting other parts of the program from extensive modification if the design decisio ...
in the presence of pointers; * ''"transfer of ownership"'' (avoidance of semantic frame axioms); and * virtual separation (modular reasoning) between concurrent modules. Separation logic supports the developing field of research described by Peter O'Hearn and others as ''local reasoning'', whereby specifications and proofs of a program component mention only the portion of memory used by the component, and not the entire global state of the system. Applications include automated
program verification In the context of hardware and software systems, formal verification is the act of proving or disproving the correctness of intended algorithms underlying a system with respect to a certain formal specification or property, using formal metho ...
(where an
algorithm In mathematics and computer science, an algorithm () is a finite sequence of rigorous instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing ...
checks the validity of another algorithm) and automated
parallelization Parallel computing is a type of computation Computation is any type of arithmetic or non-arithmetic calculation that follows a well-defined model (e.g., an algorithm). Mechanical or electronic devices (or, historically, people) that perform ...
of software.


Assertions: operators and semantics

Separation logic assertions describe "states" consisting of a ''store'' and a ''heap'', roughly corresponding to the state of local (or ''stack-allocated'') variables and ''dynamically-allocated'' objects in common programming languages such as C and
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
. A store s is a
function Function or functionality may refer to: Computing * Function key, a type of key on computer keyboards * Function model, a structured representation of processes in a system * Function object or functor or functionoid, a concept of object-oriente ...
mapping variables to values. A heap h is a
partial function In mathematics, a partial function from a set to a set is a function from a subset of (possibly itself) to . The subset , that is, the domain of viewed as a function, is called the domain of definition of . If equals , that is, if is de ...
mapping memory addresses to values. Two heaps h and h' are ''disjoint'' (denoted h \,\bot\, h') if their domains do not overlap (i.e., for every memory address \ell, at least one of h(\ell) and h'(\ell) is undefined). The logic allows to prove judgements of the form s, h \models P, where s is a store, h is a heap, and P is an ''assertion'' over the given store and heap. Separation logic assertions (denoted as P, Q, R) contain the standard boolean connectives and, in addition, \mathbf\mathbf\mathbf, e \mapsto e', P \ast Q, and P \, Q, where e and e' are expressions. * The constant \mathbf\mathbf\mathbf asserts that the heap is ''empty'', i.e., s, h \models \mathbf\mathbf\mathbf when h is undefined for all addresses. * The binary operator \mapsto takes an address and a value and asserts that the heap is defined at exactly one location, mapping the given address to the given value. I.e., s, h \models e \mapsto e' when h( ![e!.html"_;"title=".html"_;"title="![e">![e!">.html"_;"title="![e">![e!)_=_[\![e'.html" ;"title="">![e!.html" ;"title=".html" ;"title="![e">![e!">.html" ;"title="![e">![e!) = [\![e'">">![e!.html" ;"title=".html" ;"title="![e">![e!">.html" ;"title="![e">![e!) = [\![e'!]_ (where ![e!.html" ;"title=".html" ;"title="![e">![e!">.html" ;"title="!
![e!_denotes_the_value_of_expression_e_evaluated_in_store_s)_and_h_is_otherwise_undefined. *_The_binary_operator_\ast_(pronounced_''star''_or_''separating_conjunction'')_asserts_that_the_heap_can_be_split_into_two_''disjoint''_parts_where_its_two_arguments_hold,_respectively._I.e.,_s,_h_\models_P_\ast_Q_when_there_exist_h_1,_h_2_such_that_h_1_\,\bot\,_h_2_and_h_=_h_1_\cup_h_2_and_s,_h_1_\models_P_and_s,_h_2_\models_Q. *_The_binary_operator_-\!\!\ast_(pronounced_''magic_wand''_or_''separating_implication'')_asserts_that_extending_the_heap_with_a_disjoint_part_that_satisfies_its_first_argument_results_in_a_heap_that_satisfies_its_second_argument._I.e,._s,_h_\models_P_-\!\!\ast\,_Q_when_for_every_heap_h'_\,\bot\,_h_such_that_s,_h'_\models_P,_also_s,_h_\cup_h'_\models_Q_holds. The_operators_\ast_and_-\!\!\ast_share_some_properties_with_the_classical_ ![e!_denotes_the_value_of_expression_e_evaluated_in_store_s)_and_h_is_otherwise_undefined. *_The_binary_operator_\ast_(pronounced_''star''_or_''separating_conjunction'')_asserts_that_the_heap_can_be_split_into_two_''disjoint''_parts_where_its_two_arguments_hold,_respectively._I.e.,_s,_h_\models_P_\ast_Q_when_there_exist_h_1,_h_2_such_that_h_1_\,\bot\,_h_2_and_h_=_h_1_\cup_h_2_and_s,_h_1_\models_P_and_s,_h_2_\models_Q. *_The_binary_operator_-\!\!\ast_(pronounced_''magic_wand''_or_''separating_implication'')_asserts_that_extending_the_heap_with_a_disjoint_part_that_satisfies_its_first_argument_results_in_a_heap_that_satisfies_its_second_argument._I.e,._s,_h_\models_P_-\!\!\ast\,_Q_when_for_every_heap_h'_\,\bot\,_h_such_that_s,_h'_\models_P,_also_s,_h_\cup_h'_\models_Q_holds. The_operators_\ast_and_-\!\!\ast_share_some_properties_with_the_classical_Logical_Conjunction">conjunction_ Conjunction_may_refer_to: *_Conjunction_(grammar),_a_part_of_speech *_Logical_conjunction,_a_mathematical_operator **_Conjunction_introduction,_a_rule_of_inference_of_propositional_logic *_Conjunction_(astronomy),_in_which_two_astronomical_bodies__...
_and_Entailment.html" ;"title="Logical_Conjunction.html" "title="">![e! denotes the value of expression e evaluated in store s) and h is otherwise undefined. * The binary operator \ast (pronounced ''star'' or ''separating conjunction'') asserts that the heap can be split into two ''disjoint'' parts where its two arguments hold, respectively. I.e., s, h \models P \ast Q when there exist h_1, h_2 such that h_1 \,\bot\, h_2 and h = h_1 \cup h_2 and s, h_1 \models P and s, h_2 \models Q. * The binary operator -\!\!\ast (pronounced ''magic wand'' or ''separating implication'') asserts that extending the heap with a disjoint part that satisfies its first argument results in a heap that satisfies its second argument. I.e,. s, h \models P -\!\!\ast\, Q when for every heap h' \,\bot\, h such that s, h' \models P, also s, h \cup h' \models Q holds. The operators \ast and -\!\!\ast share some properties with the classical Logical Conjunction">conjunction Conjunction may refer to: * Conjunction (grammar), a part of speech * Logical conjunction, a mathematical operator ** Conjunction introduction, a rule of inference of propositional logic * Conjunction (astronomy), in which two astronomical bodies ...
and Entailment">implication operators. They can be combined using an inference rule similar to modus ponens :\frac and they form an adjunction (category theory), adjunction, i.e., s, h \cup h' \models P \ast Q \Rightarrow R if and only if s, h \models P \Rightarrow Q -\!\!\ast\, R for h \,\bot\, h'; more precisely, the adjoint operators are \_ \ast Q and Q -\!\!\ast\, \_.


Reasoning about programs: triples and proof rules

In separation logic, Hoare triples have a slightly different meaning than in Hoare logic. The triple \\ C\ \ asserts that if the program C executes from an initial state satisfying the precondition P then the program will ''not go wrong'' (e.g., have undefined behaviour), and if it terminates, then the final state will satisfy the postcondition Q. In essence, during its execution, C may access only memory locations whose existence is asserted in the precondition or that have been allocated by C itself. In addition to the standard rules from Hoare logic, separation logic supports the following very important rule: \frac~\mathsf(C) \cap \mathsf(R) =\emptyset This is known as the frame rule (named after the
frame problem In artificial intelligence, the frame problem describes an issue with using first-order logic (FOL) to express facts about a robot in the world. Representing the state of a robot with traditional FOL requires the use of many axioms that simply impl ...
) and enables local reasoning. It says that a program that executes safely in a small state (satisfying P), can also execute in any bigger state (satisfying P \ast R) and that its execution will not affect the additional part of the state (and so R will remain true in the postcondition). The side condition enforces this by specifying that none of the variables modified by C occur free in R, i.e. none of them are in the 'free variable' set \mathsf of R.


Sharing

Separation logic leads to simple proofs of pointer manipulation for data structures that exhibit regular sharing patterns which can be described simply using separating conjunctions; examples include singly and doubly linked lists and varieties of trees. Graphs and DAGs and other data structures with more general sharing are more difficult for both formal and informal proof. Separation logic has, nonetheless, been applied successfully to reasoning about programs with general sharing. In their POPL'01 paper, O'Hearn and Ishtiaq explained how the magic wand connective could be used to reason in the presence of sharing, at least in principle. For example, in the triple \\ = 42\ \ we obtain the weakest precondition for a statement that mutates the heap at location x , and this works for any postcondition, not only one that is laid out neatly using the separating conjunction. This idea was taken much further by Yang, who used to provide localized reasoning about mutations in the classic Schorr-Waite graph marking algorithm. Finally, one of the most recent works in this direction is that of Hobor and Villard, who employ not only but also a connective \cup \,\!\!\!\!\!* which has variously been called overlapping conjunction or sepish, and which can be used to describe overlapping data structures: P \cup \!\!\!\!\!* Q holds of a heap h when P and Q hold for subheaps h_P and h_Q whose union is h, but which possibly have a nonempty portion h_P \cap h_Q in common. Abstractly, P \cup \!\!\!\!\!* Q can be seen to be a version of the fusion connective of
relevance logic Relevance logic, also called relevant logic, is a kind of non-classical logic requiring the antecedent and consequent of implications to be relevantly related. They may be viewed as a family of substructural or modal logics. It is generally, but ...
.


Concurrent separation logic

A Concurrent Separation Logic (CSL), a version of separation logic for concurrent programs, was originally proposed by Peter O'Hearn, using a proof rule : \frac which allows independent reasoning about threads that access separate storage. O'Hearn's proof rules adapted an early approach of
Tony Hoare Sir Charles Antony Richard Hoare (Tony Hoare or C. A. R. Hoare) (born 11 January 1934) is a British computer scientist who has made foundational contributions to programming languages, algorithms, operating systems, formal verification, and ...
to reasoning about concurrency, replacing the use of scoping constraints to ensure separation by reasoning in separation logic. In addition to extending Hoare's approach to apply in the presence of heap-allocated pointers, O'Hearn showed how reasoning in concurrent separation logic could track dynamic ownership transfer of heap portions between processes; examples in the paper include a pointer-transferring buffer, and a memory manager. Commenting on the early classical work on interference freedom by
Susan Owicki Susan Owicki is a computer scientist, Association for Computing Machinery (ACM) Fellow, and one of the founding members of the Systers mailing list for women in computing. She changed careers in the early 2000s and became a licensed marriage ...
and
David Gries David Gries (born April 26, 1939 in Flushing, Queens, New York) is an American computer scientist at Cornell University, United States mainly known for his books ''The Science of Programming'' (1981) and ''A Logical Approach to Discrete Math' ...
, O'Hearn says that explicit checking for non-interference isn't necessary because his system rules out interference in an implicit way, by the nature of the way proofs are constructed. A model for concurrent separation logic was first provided by Stephen Brookes in a companion paper to O'Hearn's. The soundness of the logic had been a difficult problem, and in fact a counterexample of John Reynolds had shown the unsoundness of an earlier, unpublished version of the logic; the issue raised by Reynolds's example is described briefly in O'Hearn's paper, and more thoroughly in Brookes's. At first it appeared that CSL was well suited to what Dijkstra had called loosely connected processes, but perhaps not to fine-grained concurrent algorithms with significant interference. However, gradually it was realized that the basic approach of CSL was considerably more powerful than first envisaged, if one employed non-standard models of the logical connectives and even the Hoare triples. An abstract version of separation logic was proposed that works for Hoare triples where the preconditions and postconditions are formulae interpreted over an arbitrary partial commutative monoid instead of a particular heap model. Later, by suitable choice of commutative monoid, it was surprisingly found that the proof rules of abstract versions of concurrent separation logic could be used to reason about interfering concurrent processes, for example by encoding the rely-guarantee technique which had been originally proposed to reason about interference; in this work the elements of the model were considered not resources, but rather "views" of the program state, and a non-standard interpretation of Hoare triples accompanies the non-standard reading of pre and postconditions. Finally, CSL-style principles have been used to compose reasoning about program histories instead of program states, in order to provide modular techniques for reasoning about fine-grained concurrent algorithms. Versions of CSL have been included in many interactive and semi-automatic (or "in-between") verification tools as described in the next section. A particularly significant verification effort is that of the μC/OS-II kernel mentioned there. But, although steps have been made, as of yet CSL-style reasoning has been included in comparatively few tools in the automatic program analysis category (and none mentioned in the next section). O'Hearn and Brookes are co-recipients of the 2016
Gödel Prize The Gödel Prize is an annual prize for outstanding papers in the area of theoretical computer science, given jointly by the European Association for Theoretical Computer Science (EATCS) and the Association for Computing Machinery Special Interes ...
for their invention of Concurrent Separation Logic.


Verification and program analysis tools

Tools for reasoning about programs fall on a spectrum from fully automatic program analysis tools, which do not require any user input, to interactive tools where the human is intimately involved in the proof process. Many such tools have been developed; the following list includes a few representatives in each category. *Automatic Program Analyses. These tools typically look for restricted classes of bugs (e.g., memory safety errors) or attempt to prove their absence, but fall short of proving full correctness. ** A current example is Facebook Infer, a static analysis tool for Java, C, and
Objective-C Objective-C is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language. Originally developed by Brad Cox and Tom Love in the early 1980s, it was selected by NeXT for its NeXT ...
based on separation logic and bi-abduction. As of 2015 hundreds of bugs per month were being found by Infer and fixed by developers before being shipped to Facebook's mobile apps ** Other examples includ
SpaceInvader
(one of the first SL analyzers)
Predator
(which has won several verification competitions)

(which mixes shape and numerical properties) an
SLAyer
(from Microsoft Research, focussed on data structures found in device drivers) *Interactive Proof. Proofs have been done using embeddings of Separation Logic into interactive theorem provers such as the Coq proof assistant and
HOL (proof assistant) HOL (Higher Order Logic) denotes a family of interactive theorem proving systems using similar (higher-order) logics and implementation strategies. Systems in this family follow the LCF approach as they are implemented as a library which defin ...
. In comparison to the program analysis work, these tools require more in the way of human effort but prove deeper properties, up to functional correctness. ** A proof of the FSCQ file system where the specification includes behaviour under crashes as well as normal operation. This work won the best paper award at the 2015 Symposium on Operating System Principles. ** Verification of a large fragment of the
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO( ...
type system and some of its standard libraries in th
RustBelt project
using th
Iris
framework for separation logic in The Coq proof assistant. ** Verification of an OpenSSL implementation of a cryptographic authentication algorithm, utilizin
verifiable C
** Verification of key modules of a commercial OS kernel, the μC/OS-II kernel, the first commercial ''pre-emptive'' kernel to have been verified. ** Other examples include the Ynot library for the Coq proof assistant; th
Holfoot
embedding of Smallfoot in HOL
Fine-grained Concurrent Separation Logic
an
Bedrock
(a Coq library for low-level programming). *In Between. Many tools require more user intervention than program analyses, in that they expect the user to input assertions such as pre/post specs for functions or loop invariants, but after this input is given they attempt to be fully or almost fully automatic; this mode of verification goes back to classic works in the 1970s such as J King's verifier, and the Stanford Pascal Verifier. This style of verifier has recently been calle
auto active verification
a term which intends to evoke the way of interacting with a verifier via an assert-check loop, analogous to the interaction between a programmer and a type-checker. ** The very first Separation Logic verifier
Smallfoot
was in this in-between category. It required the user to input pre/post specs, loop invariants, and resource invariants for locks. It introduced a method of symbolic execution, as well as an automatic way to infer frame axioms. Smallfoot included Concurrent Separation Logic. *
SmallfootRG
is a verifier for a marriage of separation logic and the classic rely/guarantee method for concurrent programs. *
Heap Hop
implements a separation logic for message passing, following the ideas in
Singularity (operating system) Singularity is an experimental operating system developed by Microsoft Research between July 9, 2003, and February 7, 2015. It was designed as a high dependability OS in which the kernel, device drivers, and application software were all writte ...
. *
VeriFast
is an advanced current tool in the in-between category. It has demonstrated proofs ranging from object-oriented patterns to highly concurrent algorithms and to systems programs. *
Viper
is a state-of-the-art automated verification infrastructure for permission-based reasoning. It mainly consists of a programming language and two verification backends, one based on symbolic execution and another one on verification condition generation (VCG).Viper: A Verification Infrastructure for Permission-Based Reasoning
P. Müller, M. Schwerhoff, and A. J. Summers, VMCAI'16
Based on the Viper infrastructure, several frontends for various programming languages have emerged
Gobra
for Go

for Python
Prusti
for Rust, an
VerCors
for C, Java, OpenCL, and OpenMP. These frontends translate the frontend programming language into Viper to then use a Viper verification backend for proving the input program's correctness. ** Th
Mezzo Programming Language
an
Asynchronous Liquid Separation Types
include ideas related to CSL in the type system for a programming language. The idea to include separation in a type system has earlier examples i
Alias Types
an
Syntactic Control of Interference
The distinction between interactive and in-between verifiers is not a sharp one. For example, Bedrock strives for a high degree of automation, in what it terms mostly-automatic verification, where Verifast sometimes requires annotations that resemble the tactics (little programs) used in interactive verifiers.


References

{{Program analysis 2002 introductions Program logic Substructural logic Logic in computer science